namespace DotNetNuke.Services.Localization
{
    using DotNetNuke.Common;
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Host;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Entities.Tabs;
    using DotNetNuke.Entities.Users;
    using DotNetNuke.Security;
    using DotNetNuke.Services.Log.EventLog;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Diagnostics;
    using System.Globalization;
    using System.IO;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Threading;
    using System.Web;
    using System.Web.Caching;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Xml;

    public class Localization
    {
        private static string _defaultKeyName = "resourcekey";
        private static ListItem[] _timeZoneListItems;
        public const string ApplicationResourceDirectory = "~/App_GlobalResources";
        public const string GlobalResourceFile = "~/App_GlobalResources/GlobalResources.resx";
        internal const string keyConst = "resourcekey";
        public const string LocalResourceDirectory = "App_LocalResources";
        public const string LocalSharedResourceFile = "SharedResources.resx";
        public const string SharedResourceFile = "~/App_GlobalResources/SharedResources.resx";
        public const string SupportedLocalesFile = "~/App_GlobalResources/Locales.xml";
        public const string SystemLocale = "en-US";
        public const int SystemTimeZoneOffset = -480;
        public const string TimezonesFile = "~/App_GlobalResources/TimeZones.xml";

        public string AddLocale(string Key, string Name)
        {
            string result;
            XmlDocument resDoc = new XmlDocument();
            resDoc.Load(HttpContext.Current.Server.MapPath("~/App_GlobalResources/Locales.xml"));
            if (resDoc.SelectSingleNode("//root/language[@key='" + Key + "']") != null)
            {
                return "Duplicate.ErrorMessage";
            }
            XmlNode node = resDoc.CreateElement("language");
            XmlAttribute a = resDoc.CreateAttribute("name");
            a.Value = Name;
            node.Attributes.Append(a);
            a = resDoc.CreateAttribute("key");
            a.Value = Key;
            node.Attributes.Append(a);
            a = resDoc.CreateAttribute("fallback");
            a.Value = "en-US";
            node.Attributes.Append(a);
            resDoc.SelectSingleNode("//root").AppendChild(node);
            try
            {
                resDoc.Save(HttpContext.Current.Server.MapPath("~/App_GlobalResources/Locales.xml"));
                if (!File.Exists(HttpContext.Current.Server.MapPath(this.TimeZoneFile("~/App_GlobalResources/TimeZones.xml", Key))))
                {
                    File.Copy(HttpContext.Current.Server.MapPath("~/App_GlobalResources/TimeZones.xml"), HttpContext.Current.Server.MapPath(this.TimeZoneFile("~/App_GlobalResources/TimeZones.xml", Key)));
                    result = "NewLocale.ErrorMessage";
                }
                result = "";
            }
            catch (Exception exception1)
            {
                
                result = "Save.ErrorMessage";
                
            }
            return result;
        }

        public static LocaleCollection GetEnabledLocales()
        {
            string cacheKey = "";
            PortalSettings objPortalSettings = PortalController.GetCurrentPortalSettings();
            string FilePath = HttpContext.Current.Server.MapPath("~/App_GlobalResources/Locales.Portal-" + objPortalSettings.PortalId.ToString() + ".xml");
            if (File.Exists(FilePath))
            {
                cacheKey = "dotnetnuke-enabledlocales" + objPortalSettings.PortalId.ToString();
                if (DataCache.GetCache(cacheKey) == null)
                {
                    LocaleCollection enabledLocales = new LocaleCollection();
                    XmlDocument xmlInactiveLocales = new XmlDocument();
                    bool bXmlLoaded = false;
                    try
                    {
                        xmlInactiveLocales.Load(FilePath);
                        bXmlLoaded = true;
                    }
                    catch (Exception exception1)
                    {
                        
                        
                    }
                    CacheDependency dp = new CacheDependency(FilePath);
                    new XmlDocument().Load(FilePath);
                    LocaleCollection _SupportedLocales = GetSupportedLocales();
                    foreach (string _LocaleCode in _SupportedLocales.AllKeys)
                    {
                        if (((!bXmlLoaded || (xmlInactiveLocales.SelectSingleNode("//locales/inactive/locale[.='" + _LocaleCode + "']") == null)) ? 1 : 0) != 0)
                        {
                            Locale objLocale = new Locale();
                            objLocale.Text = _SupportedLocales[_LocaleCode].Text;
                            objLocale.Code = _LocaleCode;
                            objLocale.Fallback = _SupportedLocales[_LocaleCode].Fallback;
                            enabledLocales.Add(_LocaleCode, objLocale);
                        }
                    }
                    if (DotNetNuke.Common.Globals.PerformanceSetting == DotNetNuke.Common.Globals.PerformanceSettings.NoCaching)
                    {
                        return enabledLocales;
                    }
                    DataCache.SetCache(cacheKey, enabledLocales, dp);
                }
                return (LocaleCollection) DataCache.GetCache(cacheKey);
            }
            return GetSupportedLocales();
        }

        public string GetFixedCurrency(decimal Expression, string Culture, [Optional, DefaultParameterValue(-1)] int NumDigitsAfterDecimal, [Optional, DefaultParameterValue((Microsoft.VisualBasic.TriState)(-2))] Microsoft.VisualBasic.TriState IncludeLeadingDigit, [Optional, DefaultParameterValue((Microsoft.VisualBasic.TriState)(-2))] Microsoft.VisualBasic.TriState UseParensForNegativeNumbers, [Optional, DefaultParameterValue((Microsoft.VisualBasic.TriState)(-2))] Microsoft.VisualBasic.TriState GroupDigits)
        {
            string oldCurrentCulture = this.CurrentCulture;
            CultureInfo newCulture = new CultureInfo(Culture);
            Thread.CurrentThread.CurrentUICulture = newCulture;
            Thread.CurrentThread.CurrentCulture = newCulture;
            string currencyStr = Strings.FormatCurrency(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit, UseParensForNegativeNumbers, GroupDigits);
            CultureInfo oldCulture = new CultureInfo(oldCurrentCulture);
            Thread.CurrentThread.CurrentUICulture = oldCulture;
            Thread.CurrentThread.CurrentCulture = oldCulture;
            return currencyStr;
        }

        public string GetFixedDate(DateTime Expression, string Culture, [Optional, DefaultParameterValue((DateFormat)0)] DateFormat NamedFormat, [Optional, DefaultParameterValue((Microsoft.VisualBasic.TriState)(-2))] Microsoft.VisualBasic.TriState IncludeLeadingDigit, [Optional, DefaultParameterValue((Microsoft.VisualBasic.TriState)(-2))] Microsoft.VisualBasic.TriState UseParensForNegativeNumbers, [Optional, DefaultParameterValue((Microsoft.VisualBasic.TriState)(-2))] Microsoft.VisualBasic.TriState GroupDigits)
        {
            string oldCurrentCulture = this.CurrentCulture;
            CultureInfo newCulture = new CultureInfo(Culture);
            Thread.CurrentThread.CurrentUICulture = newCulture;
            Thread.CurrentThread.CurrentCulture = newCulture;
            string dateStr = Strings.FormatDateTime(Expression, NamedFormat);
            CultureInfo oldCulture = new CultureInfo(oldCurrentCulture);
            Thread.CurrentThread.CurrentUICulture = oldCulture;
            Thread.CurrentThread.CurrentCulture = oldCulture;
            return dateStr;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetResource is used by GetString to load the resources Hashtable
        /// </summary>
        /// <remarks>
        /// The priority of cultures is User &gt; Portal Default &gt; FallBack
        /// 
        /// Therefore the logic used is the following:
        /// 1. Load the fallback language resources first (these are known
        /// to exist, thus making sure that all keys are loaded)
        /// 2. Next load the Portal's default language if different (any keys that
        /// are present overwrite the fallback keys).
        /// 3. Last load the user's language if different from either of the above
        /// (again any keys that are present overwrite the fallback/default keys).
        /// 
        /// </remarks>
        /// <param name="ResourceFileRoot">The Local Resource root</param>
        /// <param name="objPortalSettings">The current portals Portal Settings</param>
        /// <returns>The rsources Hashtable </returns>
        /// <history>
        /// [cnurse]	10/06/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        private static Hashtable GetResource(string ResourceFileRoot, PortalSettings objPortalSettings)
        {
            return GetResource(ResourceFileRoot, objPortalSettings, null);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetResource is used by GetString to load the resources Hashtable
        /// </summary>
        /// <remarks>
        /// The priority of cultures is User &gt; Portal Default &gt; FallBack
        /// 
        /// Therefore the logic used is the following:
        /// 1. Load the fallback language resources first (these are known
        /// to exist, thus making sure that all keys are loaded)
        /// 2. Next load the Portal's default language if different (any keys that
        /// are present overwrite the fallback keys).
        /// 3. Last load the user's language if different from either of the above
        /// (again any keys that are present overwrite the fallback/default keys).
        /// 
        /// </remarks>
        /// <param name="ResourceFileRoot">The Local Resource root</param>
        /// <param name="objPortalSettings">The current portals Portal Settings</param>
        /// <param name="strLanguage">A specific language used to get the resource</param>
        /// <returns>The resources Hashtable </returns>
        /// <history>
        /// [cnurse]	10/06/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        private static Hashtable GetResource(string ResourceFileRoot, PortalSettings objPortalSettings, string strLanguage)
        {
            string userLanguage;
            string defaultLanguage = objPortalSettings.DefaultLanguage.ToLower();
            if (strLanguage == null)
            {
                userLanguage = Thread.CurrentThread.CurrentCulture.ToString().ToLower();
            }
            else
            {
                userLanguage = strLanguage;
            }
            string fallbackLanguage = "en-US".ToLower();
            if (userLanguage == "")
            {
                userLanguage = defaultLanguage;
            }
            if ((((GetSupportedLocales()[userLanguage] != null) && (GetSupportedLocales()[userLanguage].Fallback.ToLower() != "")) ? 1 : 0) != 0)
            {
                fallbackLanguage = GetSupportedLocales()[userLanguage].Fallback.ToLower();
            }
            string userFile = GetResourceFileName(ResourceFileRoot, userLanguage);
            string cacheKey = HttpContext.Current.Server.MapPath(userFile).Replace(DotNetNuke.Common.Globals.ApplicationMapPath, "").ToLower() + objPortalSettings.PortalId.ToString();
            Hashtable resources = (Hashtable) DataCache.GetCache(cacheKey);
            if (resources == null)
            {
                resources = new Hashtable();
                string fallbackFile = GetResourceFileName(ResourceFileRoot, fallbackLanguage);
                resources = LoadResource(LoadResource(resources, fallbackLanguage, cacheKey, fallbackFile, false, objPortalSettings), fallbackLanguage, cacheKey, fallbackFile, true, objPortalSettings);
                if ((((defaultLanguage != "") && (defaultLanguage != fallbackLanguage)) ? 1 : 0) != 0)
                {
                    string defaultFile = GetResourceFileName(ResourceFileRoot, defaultLanguage);
                    resources = LoadResource(LoadResource(resources, defaultLanguage, cacheKey, defaultFile, false, objPortalSettings), defaultLanguage, cacheKey, defaultFile, true, objPortalSettings);
                }
                if ((((userLanguage != defaultLanguage) && (userLanguage != fallbackLanguage)) ? 1 : 0) != 0)
                {
                    resources = LoadResource(LoadResource(resources, userLanguage, cacheKey, userFile, false, objPortalSettings), userLanguage, cacheKey, userFile, true, objPortalSettings);
                }
            }
            return resources;
        }

        public static string GetResourceFile(Control Ctrl, string FileName)
        {
            return (Ctrl.TemplateSourceDirectory + "/App_LocalResources/" + FileName);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetResourceFileName is used to build the resource file name according to the
        /// language
        /// </summary>
        /// <param name="language">The language</param>
        /// <param name="ResourceFileRoot">The resource file root</param>
        /// <returns>The language specific resource file</returns>
        /// <history>
        /// [cnurse]	10/06/2004	created
        /// </history>
        /// -----------------------------------------------------------------------------
        private static string GetResourceFileName(string ResourceFileRoot, string language)
        {
            if (ResourceFileRoot != null)
            {
                if ((language == "en-US".ToLower()) | (language == ""))
                {
                    switch (Strings.Right(ResourceFileRoot, 5).ToLower())
                    {
                        case ".resx":
                            return ResourceFileRoot;

                        case ".ascx":
                            return (ResourceFileRoot + ".resx");
                    }
                    return (ResourceFileRoot + ".ascx.resx");
                }
                switch (Strings.Right(ResourceFileRoot, 5).ToLower())
                {
                    case ".resx":
                        return ResourceFileRoot.Replace(".resx", "." + language + ".resx");

                    case ".ascx":
                        return ResourceFileRoot.Replace(".ascx", ".ascx." + language + ".resx");
                }
                return (ResourceFileRoot + ".ascx." + language + ".resx");
            }
            if ((language == "en-US".ToLower()) | (language == ""))
            {
                return "~/App_GlobalResources/SharedResources.resx";
            }
            return "~/App_GlobalResources/SharedResources.resx".Replace(".resx", "." + language + ".resx");
        }

        /// -----------------------------------------------------------------------------
        /// <overloads>One of five overloads</overloads>
        /// <summary>
        /// GetString gets the localized string corresponding to the resourcekey
        /// </summary>
        /// <param name="name">The resourcekey to find</param>
        /// <returns>The localized Text</returns>
        /// <history>
        /// [cnurse]	10/06/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetString(string name)
        {
            PortalSettings objPortalSettings = (PortalSettings) HttpContext.Current.Items["PortalSettings"];
            return GetString(name, null, objPortalSettings, null);
        }

        /// -----------------------------------------------------------------------------
        /// <overloads>One of five overloads</overloads>
        /// <summary>
        /// GetString gets the localized string corresponding to the resourcekey
        /// </summary>
        /// <param name="name">The resourcekey to find</param>
        /// <param name="objPortalSettings">The current portals Portal Settings</param>
        /// <returns>The localized Text</returns>
        /// <history>
        /// [cnurse]	10/06/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetString(string name, PortalSettings objPortalSettings)
        {
            return GetString(name, null, objPortalSettings, null);
        }

        /// -----------------------------------------------------------------------------
        /// <overloads>One of five overloads</overloads>
        /// <summary>
        /// GetString gets the localized string corresponding to the resourcekey
        /// </summary>
        /// <param name="name">The resourcekey to find</param>
        /// <param name="ResourceFileRoot">The Local Resource root</param>
        /// <returns>The localized Text</returns>
        /// <history>
        /// [cnurse]	10/06/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetString(string name, string ResourceFileRoot)
        {
            PortalSettings objPortalSettings = (PortalSettings) HttpContext.Current.Items["PortalSettings"];
            return GetString(name, ResourceFileRoot, objPortalSettings, null);
        }

        /// -----------------------------------------------------------------------------
        /// <overloads>One of five overloads</overloads>
        /// <summary>
        /// GetString gets the localized string corresponding to the resourcekey
        /// </summary>
        /// <param name="name">The resourcekey to find</param>
        /// <param name="ResourceFileRoot">The Local Resource root</param>
        /// <param name="strLanguage">A specific language to lookup the string</param>
        /// <returns>The localized Text</returns>
        /// <history>
        /// [cnurse]	10/06/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetString(string name, string ResourceFileRoot, string strlanguage)
        {
            PortalSettings objPortalSettings = (PortalSettings) HttpContext.Current.Items["PortalSettings"];
            return GetString(name, ResourceFileRoot, objPortalSettings, strlanguage);
        }

        /// -----------------------------------------------------------------------------
        /// <overloads>One of five overloads</overloads>
        /// <summary>
        /// GetString gets the localized string corresponding to the resourcekey
        /// </summary>
        /// <param name="name">The resourcekey to find</param>
        /// <param name="ResourceFileRoot">The Local Resource root</param>
        /// <param name="objPortalSettings">The current portals Portal Settings</param>
        /// <param name="strLanguage">A specific language to lookup the string</param>
        /// <returns>The localized Text</returns>
        /// <history>
        /// [cnurse]	10/06/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetString(string name, string ResourceFileRoot, PortalSettings objPortalSettings, string strLanguage)
        {
            Hashtable resources = GetResource(ResourceFileRoot, objPortalSettings, strLanguage);
            if (name.IndexOf(".") < 1)
            {
                name = name + ".Text";
            }
            if ((((resources == null) || (resources[name] == null)) ? 1 : 0) != 0)
            {
                resources = GetResource("~/App_GlobalResources/SharedResources.resx", objPortalSettings);
            }
            if ((((resources == null) || (resources[name] == null)) ? 1 : 0) != 0)
            {
                bool showMissingKeys;
                Debug.WriteLine("Value not found in resources.xml for: " + name + " in " + ResourceFileRoot);
                if (Config.GetSetting("ShowMissingKeys") == null)
                {
                    showMissingKeys = false;
                }
                else
                {
                    showMissingKeys = bool.Parse(Config.GetSetting("ShowMissingKeys"));
                }
                if (showMissingKeys)
                {
                    new EventLogController().AddLog("Key Missing for: ", name + " in " + ResourceFileRoot, objPortalSettings, Null.NullInteger, EventLogController.EventLogType.ADMIN_ALERT);
                    return ("RESX:" + name);
                }
            }
            return Conversions.ToString(resources[name]);
        }

        /// <summary>
        /// <para>GetSupportedLocales returns the list of locales from the locales.xml file.</para>
        /// </summary>
        public static LocaleCollection GetSupportedLocales()
        {
            string cacheKey = "dotnetnuke-supportedlocales";
            if (DataCache.GetCache(cacheKey) == null)
            {
                IEnumerator refObjectHelperL0=null;
                LocaleCollection supportedLocales = new LocaleCollection();
                string filePath = DotNetNuke.Common.Globals.ApplicationMapPath + "~/App_GlobalResources/Locales.xml".Substring(1).Replace("/", @"\");
                if (!File.Exists(filePath))
                {
                    try
                    {
                        File.Copy(DotNetNuke.Common.Globals.ApplicationMapPath + "~/App_GlobalResources".Substring(1).Replace("/", @"\") + @"\Locales.xml.resources", DotNetNuke.Common.Globals.ApplicationMapPath + "~/App_GlobalResources/Locales.xml".Substring(1).Replace("/", @"\"));
                    }
                    catch (Exception exception1)
                    {
                        
                        Locale objLocale = new Locale();
                        objLocale.Text = "English";
                        objLocale.Code = "en-US";
                        objLocale.Fallback = "";
                        supportedLocales.Add("en-US", objLocale);
                        LocaleCollection GetSupportedLocales = supportedLocales;
                        
                        return GetSupportedLocales;
                        
                    }
                }
                CacheDependency dp = new CacheDependency(filePath);
                XmlDocument d = new XmlDocument();
                d.Load(filePath);
                try
                {
                    refObjectHelperL0 = d.SelectNodes("root/language").GetEnumerator();
                    while (refObjectHelperL0.MoveNext())
                    {
                        XmlNode n = (XmlNode) refObjectHelperL0.Current;
                        if (n.NodeType != XmlNodeType.Comment)
                        {
                            Locale objLocale = new Locale();
                            objLocale.Text = n.Attributes["name"].Value;
                            objLocale.Code = n.Attributes["key"].Value;
                            objLocale.Fallback = n.Attributes["fallback"].Value;
                            supportedLocales.Add(n.Attributes["key"].Value, objLocale);
                        }
                    }
                }
                finally
                {
                    if (refObjectHelperL0 is IDisposable)
                    {
                        (refObjectHelperL0 as IDisposable).Dispose();
                    }
                }
                if (DotNetNuke.Common.Globals.PerformanceSetting != DotNetNuke.Common.Globals.PerformanceSettings.NoCaching)
                {
                    DataCache.SetCache(cacheKey, supportedLocales, dp);
                }
                else
                {
                    return supportedLocales;
                }
            }
            return (LocaleCollection) DataCache.GetCache(cacheKey);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets a SystemMessage.
        /// </summary>
        /// <param name="objPortal">The portal settings for the portal to which the message will affect.</param>
        /// <param name="MessageName">The message tag which identifies the SystemMessage.</param>
        /// <returns>The message body with all tags replaced.</returns>
        /// <remarks>
        /// Supported tags:
        /// - All fields from HostSettings table in the form of: [Host:<b>field</b>]
        /// - All properties defined in <see cref="T:DotNetNuke.PortalInfo" /> in the form of: [Portal:<b>property</b>]
        /// - [Portal:URL]: The base URL for the portal
        /// - All properties defined in <see cref="T:DotNetNuke.UserInfo" /> in the form of: [User:<b>property</b>]
        /// - All values stored in the user profile in the form of: [Profile:<b>key</b>]
        /// - [User:VerificationCode]: User verification code for verified registrations
        /// - [Date:Current]: Current date
        /// </remarks>
        /// <history>
        /// [Vicen鏬	05/07/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetSystemMessage(PortalSettings objPortal, string MessageName)
        {
            return GetSystemMessage(null, objPortal, MessageName, null, "~/App_GlobalResources/GlobalResources.resx", null);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets a SystemMessage.
        /// </summary>
        /// <param name="objPortal">The portal settings for the portal to which the message will affect.</param>
        /// <param name="MessageName">The message tag which identifies the SystemMessage.</param>
        /// <param name="objUser">Reference to the user used to personalize the message.</param>
        /// <returns>The message body with all tags replaced.</returns>
        /// <remarks>
        /// Supported tags:
        /// - All fields from HostSettings table in the form of: [Host:<b>field</b>]
        /// - All properties defined in <see cref="T:DotNetNuke.PortalInfo" /> in the form of: [Portal:<b>property</b>]
        /// - [Portal:URL]: The base URL for the portal
        /// - All properties defined in <see cref="T:DotNetNuke.UserInfo" /> in the form of: [User:<b>property</b>]
        /// - All values stored in the user profile in the form of: [Profile:<b>key</b>]
        /// - [User:VerificationCode]: User verification code for verified registrations
        /// - [Date:Current]: Current date
        /// </remarks>
        /// <history>
        /// [Vicen鏬	05/07/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetSystemMessage(PortalSettings objPortal, string MessageName, UserInfo objUser)
        {
            return GetSystemMessage(null, objPortal, MessageName, objUser, "~/App_GlobalResources/GlobalResources.resx", null);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets a SystemMessage.
        /// </summary>
        /// <param name="objPortal">The portal settings for the portal to which the message will affect.</param>
        /// <param name="MessageName">The message tag which identifies the SystemMessage.</param>
        /// <param name="ResourceFile">The root name of the Resource File where the localized
        /// text can be found</param>
        /// <returns>The message body with all tags replaced.</returns>
        /// <remarks>
        /// Supported tags:
        /// - All fields from HostSettings table in the form of: [Host:<b>field</b>]
        /// - All properties defined in <see cref="T:DotNetNuke.PortalInfo" /> in the form of: [Portal:<b>property</b>]
        /// - [Portal:URL]: The base URL for the portal
        /// - All properties defined in <see cref="T:DotNetNuke.UserInfo" /> in the form of: [User:<b>property</b>]
        /// - All values stored in the user profile in the form of: [Profile:<b>key</b>]
        /// - [User:VerificationCode]: User verification code for verified registrations
        /// - [Date:Current]: Current date
        /// </remarks>
        /// <history>
        /// [Vicen鏬	05/07/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetSystemMessage(PortalSettings objPortal, string MessageName, string ResourceFile)
        {
            return GetSystemMessage(null, objPortal, MessageName, null, ResourceFile, null);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets a SystemMessage.
        /// </summary>
        /// <param name="objPortal">The portal settings for the portal to which the message will affect.</param>
        /// <param name="MessageName">The message tag which identifies the SystemMessage.</param>
        /// <param name="objUser">Reference to the user used to personalize the message.</param>
        /// <param name="ResourceFile">The root name of the Resource File where the localized
        /// text can be found</param>
        /// <returns>The message body with all tags replaced.</returns>
        /// <remarks>
        /// Supported tags:
        /// - All fields from HostSettings table in the form of: [Host:<b>field</b>]
        /// - All properties defined in <see cref="T:DotNetNuke.PortalInfo" /> in the form of: [Portal:<b>property</b>]
        /// - [Portal:URL]: The base URL for the portal
        /// - All properties defined in <see cref="T:DotNetNuke.UserInfo" /> in the form of: [User:<b>property</b>]
        /// - All values stored in the user profile in the form of: [Profile:<b>key</b>]
        /// - [User:VerificationCode]: User verification code for verified registrations
        /// - [Date:Current]: Current date
        /// </remarks>
        /// <history>
        /// [Vicen鏬	05/07/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetSystemMessage(PortalSettings objPortal, string MessageName, UserInfo objUser, string ResourceFile)
        {
            return GetSystemMessage(null, objPortal, MessageName, objUser, ResourceFile, null);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets a SystemMessage passing extra custom parameters to personalize.
        /// </summary>
        /// <param name="objPortal">The portal settings for the portal to which the message will affect.</param>
        /// <param name="MessageName">The message tag which identifies the SystemMessage.</param>
        /// <param name="ResourceFile">The root name of the Resource File where the localized
        /// text can be found</param>
        /// <param name="Custom">An ArrayList with replacements for custom tags.</param>
        /// <returns>The message body with all tags replaced.</returns>
        /// <remarks>
        /// Custom tags are of the form <b>[Custom:n]</b>, where <b>n</b> is the zero based index which 
        /// will be used to find the replacement value in <b>Custom</b> parameter.
        /// </remarks>
        /// <history>
        /// [Vicen鏬	05/07/2004	Documented
        /// [cnurse]    10/06/2004  Moved from SystemMessages to Localization
        /// [DanCaron]  10/27/2004  Simplified Profile replacement, added Membership replacement
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetSystemMessage(PortalSettings objPortal, string MessageName, string ResourceFile, ArrayList Custom)
        {
            return GetSystemMessage(null, objPortal, MessageName, null, ResourceFile, Custom);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ''' Gets a SystemMessage.
        /// </summary>
        /// <param name="strLanguage">A specific language to get the SystemMessage for.</param>
        /// <param name="objPortal">The portal settings for the portal to which the message will affect.</param>
        /// <param name="MessageName">The message tag which identifies the SystemMessage.</param>
        /// <param name="objUser">Reference to the user used to personalize the message.</param>
        /// <returns>The message body with all tags replaced.</returns>
        /// <remarks>
        /// Supported tags:
        /// - All fields from HostSettings table in the form of: [Host:<b>field</b>]
        /// - All properties defined in <see cref="T:DotNetNuke.PortalInfo" /> in the form of: [Portal:<b>property</b>]
        /// - [Portal:URL]: The base URL for the portal
        /// - All properties defined in <see cref="T:DotNetNuke.UserInfo" /> in the form of: [User:<b>property</b>]
        /// - All values stored in the user profile in the form of: [Profile:<b>key</b>]
        /// - [User:VerificationCode]: User verification code for verified registrations
        /// - [Date:Current]: Current date
        /// </remarks>
        /// <history>
        /// [Vicen鏬	05/07/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetSystemMessage(string strLanguage, PortalSettings objPortal, string MessageName, UserInfo objUser)
        {
            return GetSystemMessage(strLanguage, objPortal, MessageName, objUser, "~/App_GlobalResources/GlobalResources.resx", null);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets a SystemMessage passing extra custom parameters to personalize.
        /// </summary>
        /// <param name="objPortal">The portal settings for the portal to which the message will affect.</param>
        /// <param name="MessageName">The message tag which identifies the SystemMessage.</param>
        /// <param name="objUser">Reference to the user used to personalize the message.</param>
        /// <param name="ResourceFile">The root name of the Resource File where the localized
        /// text can be found</param>
        /// <param name="Custom">An ArrayList with replacements for custom tags.</param>
        /// <returns>The message body with all tags replaced.</returns>
        /// <remarks>
        /// Custom tags are of the form <b>[Custom:n]</b>, where <b>n</b> is the zero based index which 
        /// will be used to find the replacement value in <b>Custom</b> parameter.
        /// </remarks>
        /// <history>
        /// [Vicen鏬	05/07/2004	Documented
        /// [cnurse]    10/06/2004  Moved from SystemMessages to Localization
        /// [DanCaron]  10/27/2004  Simplified Profile replacement, added Membership replacement
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetSystemMessage(PortalSettings objPortal, string MessageName, UserInfo objUser, string ResourceFile, ArrayList Custom)
        {
            return GetSystemMessage(null, objPortal, MessageName, objUser, ResourceFile, Custom);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets a SystemMessage passing extra custom parameters to personalize.
        /// </summary>
        /// <param name="strLanguage">A specific language to get the SystemMessage for.</param>
        /// <param name="objPortal">The portal settings for the portal to which the message will affect.</param>
        /// <param name="MessageName">The message tag which identifies the SystemMessage.</param>
        /// <param name="objUser">Reference to the user used to personalize the message.</param>
        /// <param name="ResourceFile">The root name of the Resource File where the localized
        /// text can be found</param>
        /// <param name="Custom">An ArrayList with replacements for custom tags.</param>
        /// <returns>The message body with all tags replaced.</returns>
        /// <remarks>
        /// Custom tags are of the form <b>[Custom:n]</b>, where <b>n</b> is the zero based index which 
        /// will be used to find the replacement value in <b>Custom</b> parameter.
        /// </remarks>
        /// <history>
        /// [Vicen鏬	05/07/2004	Documented
        /// [cnurse]    10/06/2004  Moved from SystemMessages to Localization
        /// [DanCaron]  10/27/2004  Simplified Profile replacement, added Membership replacement
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string GetSystemMessage(string strLanguage, PortalSettings objPortal, string MessageName, UserInfo objUser, string ResourceFile, ArrayList Custom)
        {
            CultureInfo ci;
            string strMessageValue = GetString(MessageName, ResourceFile, strLanguage);
            if (strMessageValue == "")
            {
                return strMessageValue;
            }
            if (Strings.InStr(1, strMessageValue, "Host:", CompareMethod.Text) != 0)
            {
                IEnumerator refObjectHelperL0=null;
                Hashtable objHostSettings = HostSettings.GetSecureHostSettings();
                try
                {
                    refObjectHelperL0 = objHostSettings.Keys.GetEnumerator();
                    while (refObjectHelperL0.MoveNext())
                    {
                        string strKey = Conversions.ToString(refObjectHelperL0.Current);
                        if (Strings.InStr(1, strMessageValue, "[Host:" + strKey + "]", CompareMethod.Text) != 0)
                        {
                            strMessageValue = Strings.Replace(strMessageValue, "[Host:" + strKey + "]", objHostSettings[strKey].ToString(), 1, -1, CompareMethod.Text);
                        }
                    }
                }
                finally
                {
                    if (refObjectHelperL0 is IDisposable)
                    {
                        (refObjectHelperL0 as IDisposable).Dispose();
                    }
                }
            }
            if (Strings.InStr(1, strMessageValue, "Portal:", CompareMethod.Text) != 0)
            {
                if (objPortal != null)
                {
                    strMessageValue = PersonalizeSystemMessage(strMessageValue, "Portal:", objPortal, typeof(PortalSettings));
                }
                strMessageValue = Strings.Replace(strMessageValue, "[Portal:URL]", objPortal.PortalAlias.HTTPAlias, 1, -1, CompareMethod.Text);
            }
            if ((objUser != null) & (objPortal != null))
            {
                if (Strings.InStr(1, strMessageValue, "User:", CompareMethod.Text) != 0)
                {
                    strMessageValue = Strings.Replace(PersonalizeSystemMessage(strMessageValue, "User:", objUser, typeof(UserInfo)), "[User:VerificationCode]", objPortal.PortalId.ToString() + "-" + objUser.UserID.ToString(), 1, -1, CompareMethod.Text);
                }
                if (Strings.InStr(1, strMessageValue, "Membership:", CompareMethod.Text) != 0)
                {
                    strMessageValue = PersonalizeSystemMessage(strMessageValue, "Membership:", objUser.Membership, typeof(UserMembership));
                }
                if (Strings.InStr(1, strMessageValue, "Profile:", CompareMethod.Text) != 0)
                {
                    strMessageValue = PersonalizeSystemMessage(strMessageValue, "Profile:", objUser.Profile, typeof(UserProfile));
                }
            }
            if ((Strings.InStr(1, strMessageValue, "Custom:", CompareMethod.Text) != 0) && (Custom != null))
            {
                int refIntHelperL2 = Custom.Count - 1;
                for (int intIndex = 0; intIndex <= refIntHelperL2; intIndex++)
                {
                    strMessageValue = Strings.Replace(strMessageValue, "[Custom:" + intIndex.ToString() + "]", Custom[intIndex].ToString(), 1, -1, CompareMethod.Text);
                }
            }
            if (strLanguage != null)
            {
                ci = new CultureInfo(strLanguage);
            }
            else
            {
                ci = new CultureInfo(Thread.CurrentThread.CurrentCulture.ToString().ToLower());
            }
            return Strings.Replace(strMessageValue, "[Date:Current]", DateAndTime.Now.ToString("D", ci), 1, -1, CompareMethod.Text);
        }

        public static NameValueCollection GetTimeZones(string language)
        {
            string TranslationFile;
            language = language.ToLower();
            string cacheKey = "dotnetnuke-" + language + "-timezones";
            if (language == "en-US".ToLower())
            {
                TranslationFile = "~/App_GlobalResources/TimeZones.xml";
            }
            else
            {
                TranslationFile = "~/App_GlobalResources/TimeZones.xml".Replace(".xml", "." + language + ".xml");
            }
            if (DataCache.GetCache(cacheKey) == null)
            {
                string filePath = HttpContext.Current.Server.MapPath(TranslationFile);
                NameValueCollection timeZones = new NameValueCollection();
                if (!File.Exists(filePath))
                {
                    return timeZones;
                }
                CacheDependency dp = new CacheDependency(filePath);
                try
                {
                    IEnumerator refObjectHelperL0=null;
                    XmlDocument d = new XmlDocument();
                    d.Load(filePath);
                    try
                    {
                        refObjectHelperL0 = d.SelectSingleNode("root").ChildNodes.GetEnumerator();
                        while (refObjectHelperL0.MoveNext())
                        {
                            XmlNode n = (XmlNode) refObjectHelperL0.Current;
                            if (n.NodeType != XmlNodeType.Comment)
                            {
                                timeZones.Add(n.Attributes["name"].Value, n.Attributes["key"].Value);
                            }
                        }
                    }
                    finally
                    {
                        if (refObjectHelperL0 is IDisposable)
                        {
                            (refObjectHelperL0 as IDisposable).Dispose();
                        }
                    }
                }
                catch (Exception exception1)
                {
                    
                    Exception ex = exception1;
                    
                }
                if (DotNetNuke.Common.Globals.PerformanceSetting == DotNetNuke.Common.Globals.PerformanceSettings.NoCaching)
                {
                    return timeZones;
                }
                DataCache.SetCache(cacheKey, timeZones, dp);
            }
            return (NameValueCollection) DataCache.GetCache(cacheKey);
        }

        /// <summary>
        /// <para>LoadCultureDropDownList loads a DropDownList with the list of supported cultures
        /// based on the languages defined in the supported locales file</para>
        /// </summary>
        /// <param name="list">DropDownList to load</param>
        /// <param name="displayType">Format of the culture to display. Must be one the CultureDropDownTypes values. 
        /// <see cref="T:DotNetNuke.Services.Localization.CultureDropDownTypes" /> for list of allowable values</param>
        /// <param name="selectedValue">Name of the default culture to select</param>
        public static void LoadCultureDropDownList(DropDownList list, CultureDropDownTypes displayType, string selectedValue)
        {
            LocaleCollection supportedLanguages = GetSupportedLocales();
            ListItem[] _cultureListItems = new ListItem[(supportedLanguages.Count - 1) + 1];
            CultureDropDownTypes _cultureListItemsType = displayType;
            PortalSettings objPortalSettings = PortalController.GetCurrentPortalSettings();
            XmlDocument xmlLocales = new XmlDocument();
            bool bXmlLoaded = false;
            int intAdded = 0;
            if (File.Exists(HttpContext.Current.Server.MapPath("~/App_GlobalResources/Locales.Portal-" + objPortalSettings.PortalId.ToString() + ".xml")))
            {
                try
                {
                    xmlLocales.Load(HttpContext.Current.Server.MapPath("~/App_GlobalResources/Locales.Portal-" + objPortalSettings.PortalId.ToString() + ".xml"));
                    bXmlLoaded = true;
                }
                catch (Exception exception1)
                {
                    
                    
                }
            }
            int refIntHelperL2 = supportedLanguages.Count - 1;
            for (int i = 0; i <= refIntHelperL2; i++)
            {
                DictionaryEntry refStructHelperS0;
                if (bXmlLoaded)
                {
                    refStructHelperS0 = supportedLanguages[i];
                }
                if (((xmlLocales.SelectSingleNode("//locales/inactive/locale[.='" + ((Locale) refStructHelperS0.Value).Code + "']") == null) ? 1 : 0) != 0)
                {
                    refStructHelperS0 = supportedLanguages[i];
                    CultureInfo info = CultureInfo.CreateSpecificCulture(((Locale) refStructHelperS0.Value).Code);
                    ListItem item = new ListItem();
                    refStructHelperS0 = supportedLanguages[i];
                    item.Value = ((Locale) refStructHelperS0.Value).Code;
                    switch (((int) displayType))
                    {
                        case 1:
                            item.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(info.EnglishName);
                            break;

                        case 2:
                            item.Text = info.LCID.ToString();
                            break;

                        case 3:
                            item.Text = info.Name;
                            break;

                        case 4:
                            item.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(info.NativeName);
                            break;

                        case 5:
                            item.Text = info.TwoLetterISOLanguageName;
                            break;

                        case 6:
                            item.Text = info.ThreeLetterISOLanguageName;
                            break;

                        default:
                            item.Text = info.DisplayName;
                            break;
                    }
                    _cultureListItems[intAdded] = item;
                    intAdded++;
                }
            }
            if (list.Items.Count > 0)
            {
                list.Items.Clear();
            }
            _cultureListItems = (ListItem[]) Utils.CopyArray((Array) _cultureListItems, new ListItem[(intAdded - 1) + 1]);
            list.Items.AddRange(_cultureListItems);
            if (selectedValue != null)
            {
                ListItem item = list.Items.FindByValue(selectedValue);
                if (item != null)
                {
                    list.SelectedIndex = -1;
                    item.Selected = true;
                }
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LoadResource is used by getResource to add resources to the resources Hashtable
        /// </summary>
        /// <param name="target">The Hashtable to add resources to</param>
        /// <param name="language">The language to load</param>
        /// <param name="cacheKey">The cache key</param>
        /// <param name="ResourceFile">The language specific resource file</param>
        /// <param name="CheckCustomCulture">A flag to determine if portal specific resources are to be checked</param>
        /// <param name="objPortalSettings">The current portals Portal Settings</param>
        /// <returns>The updated resources Hashtable </returns>
        /// <history>
        /// [cnurse]	10/06/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        private static Hashtable LoadResource(Hashtable target, string language, string cacheKey, string ResourceFile, bool CheckCustomCulture, PortalSettings objPortalSettings)
        {
            string f;
            if (CheckCustomCulture)
            {
                f = ResourceFile.Replace(".resx", ".Portal-" + objPortalSettings.PortalId.ToString() + ".resx");
            }
            else
            {
                f = ResourceFile;
            }
            if ((((f == null) || !File.Exists(HttpContext.Current.Server.MapPath(f))) ? 1 : 0) != 0)
            {
                if (!f.Contains(".Portal-" + objPortalSettings.PortalId.ToString()))
                {
                    new EventLogController().AddLog("Core Localization File Not Found: ", f, objPortalSettings, Null.NullInteger, EventLogController.EventLogType.ADMIN_ALERT);
                }
                return target;
            }
            string filePath = HttpContext.Current.Server.MapPath(f);
            CacheDependency dp = new CacheDependency(filePath);
            bool xmlLoaded = false;
            XmlDocument d = new XmlDocument();
            try
            {
                d.Load(filePath);
                xmlLoaded = true;
            }
            catch (Exception exception1)
            {
                
                new EventLogController().AddLog("Localization File Load Error: ", filePath, objPortalSettings, Null.NullInteger, EventLogController.EventLogType.ADMIN_ALERT);
                xmlLoaded = false;
                
            }
            if (xmlLoaded)
            {
                IEnumerator refObjectHelperL0=null;
                try
                {
                    refObjectHelperL0 = d.SelectNodes("root/data").GetEnumerator();
                    while (refObjectHelperL0.MoveNext())
                    {
                        XmlNode n = (XmlNode) refObjectHelperL0.Current;
                        if (n.NodeType != XmlNodeType.Comment)
                        {
                            string val = n.SelectSingleNode("value").InnerText;
                            if (target[n.Attributes["name"].Value] == null)
                            {
                                target.Add(n.Attributes["name"].Value, val);
                            }
                            else
                            {
                                target[n.Attributes["name"].Value] = val;
                            }
                        }
                    }
                }
                finally
                {
                    if (refObjectHelperL0 is IDisposable)
                    {
                        (refObjectHelperL0 as IDisposable).Dispose();
                    }
                }
                int CacheMins = 3 * Convert.ToInt32((int) DotNetNuke.Common.Globals.PerformanceSetting);
                if (CacheMins > 0)
                {
                    TimeSpan refStructHelperS0 = new TimeSpan(0, CacheMins, 0);
                    DataCache.SetCache(cacheKey, target, dp, DateTime.MaxValue, refStructHelperS0);
                }
            }
            return target;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LoadTimeZoneDropDownList loads a drop down list with the Timezones
        /// </summary>
        /// <param name="list">The list to load</param>
        /// <param name="language">Language</param>
        /// <param name="selectedValue">The selected Time Zone</param>
        /// <history>
        /// [cnurse]	10/29/2004	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static void LoadTimeZoneDropDownList(DropDownList list, string language, string selectedValue)
        {
            NameValueCollection timeZones = GetTimeZones(language);
            if (timeZones.Count == 0)
            {
                timeZones = GetTimeZones("en-US".ToLower());
            }
            int refIntHelperL0 = timeZones.Keys.Count - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                list.Items.Add(new ListItem(timeZones.GetKey(i).ToString(), timeZones.Get(i).ToString()));
            }
            if (selectedValue != null)
            {
                ListItem item = list.Items.FindByValue(selectedValue);
                if (item == null)
                {
                    int refIntHelperS1 = -480;
                    item = list.Items.FindByValue(refIntHelperS1.ToString());
                }
                if (item != null)
                {
                    list.SelectedIndex = -1;
                    item.Selected = true;
                }
            }
        }

        public static bool LocaleIsEnabled(ref string localeCode)
        {
            bool LocaleIsEnabled;
            try
            {
                bool isEnabled = false;
                LocaleCollection collEnabledLocales = GetEnabledLocales();
                if (collEnabledLocales[localeCode] == null)
                {
                    if (localeCode.IndexOf("-") == -1)
                    {
                        int refIntHelperL0 = collEnabledLocales.Count - 1;
                        for (int i = 0; i <= refIntHelperL0; i++)
                        {
                            DictionaryEntry refStructHelperS0 = collEnabledLocales[i];
                            if (Conversions.ToString(refStructHelperS0.Key).Split(new char[] { '-' })[0] == localeCode)
                            {
                                refStructHelperS0 = collEnabledLocales[i];
                                localeCode = Conversions.ToString(refStructHelperS0.Key);
                                isEnabled = true;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    isEnabled = true;
                }
                LocaleIsEnabled = isEnabled;
            }
            catch (Exception exception1)
            {
                
                Exception ex = exception1;
                LocaleIsEnabled = false;
                
                return LocaleIsEnabled;
                
            }
            return LocaleIsEnabled;
        }

        public static bool LocaleIsEnabled(Locale locale)
        {
            Locale refObjectHelperS0 = locale;
            string refStringHelperS0 = refObjectHelperS0.Code;
            refObjectHelperS0.Code = refStringHelperS0;
            return LocaleIsEnabled(ref refStringHelperS0);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Localizes ModuleControl Titles
        /// </summary>
        /// <param name="ControlTitle">Current control title</param>
        /// <param name="ControlSrc">Control Source</param>
        /// <param name="Key">Control Key</param>
        /// <returns>
        /// Localized control title if found
        /// </returns>
        /// <remarks>
        /// Resource keys are: ControlTitle_[key].Text
        /// Key MUST be lowercase in the resource file
        /// </remarks>
        /// <history>
        /// [vmasanas]	08/11/2004	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string LocalizeControlTitle(string ControlTitle, string ControlSrc, string Key)
        {
            string reskey = "ControlTitle_" + Key.ToLower() + ".Text";
            string ResFile = ControlSrc.Substring(0, ControlSrc.LastIndexOf("/") + 1) + "App_LocalResources" + ControlSrc.Substring(ControlSrc.LastIndexOf("/"), ControlSrc.LastIndexOf(".") - ControlSrc.LastIndexOf("/"));
            string localizedvalue = GetString(reskey, ResFile);
            if (localizedvalue != null)
            {
                return localizedvalue;
            }
            return ControlTitle;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LocalizeDataGrid creates localized Headers for a DataGrid
        /// </summary>
        /// <param name="grid">Grid t localize</param>
        /// <param name="ResourceFile">The root name of the Resource File where the localized
        /// text can be found</param>
        /// <history>
        /// [cnurse]	9/10/2004	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static void LocalizeDataGrid(ref DataGrid grid, string ResourceFile)
        {
            IEnumerator refObjectHelperL0=null;
            try
            {
                refObjectHelperL0 = grid.Columns.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    string localizedText;
                    DataGridColumn col = (DataGridColumn) refObjectHelperL0.Current;
                    string key = col.HeaderText;
                    if (key != "")
                    {
                        localizedText = GetString(key + ".Header", ResourceFile);
                        if (localizedText != "")
                        {
                            col.HeaderText = localizedText;
                        }
                    }
                    if (col is EditCommandColumn)
                    {
                        EditCommandColumn editCol = (EditCommandColumn) col;
                        localizedText = GetString(editCol.EditText + ".EditText", ResourceFile);
                        if (localizedText != "")
                        {
                            editCol.EditText = localizedText;
                        }
                    }
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Localizes PortalSettings
        /// </summary>
        /// <remarks>
        /// Localizes:
        /// -DesktopTabs
        /// -BreadCrumbs
        /// Localized values are stored in httpcontext
        /// </remarks>
        /// <history>
        /// [vmasanas]	11/08/2004	Created
        /// [vmasanas]  12/09/2004  Localize ActiveTab
        /// </history>
        /// -----------------------------------------------------------------------------
        public static void LocalizePortalSettings()
        {
            PortalSettings objPortalSettings = (PortalSettings) HttpContext.Current.Items["PortalSettings"];
            objPortalSettings.DesktopTabs = LocalizeTabStripDetails(objPortalSettings.DesktopTabs);
            objPortalSettings.ActiveTab.BreadCrumbs = LocalizeTabStripDetails(objPortalSettings.ActiveTab.BreadCrumbs);
            if (objPortalSettings.ActiveTab.IsAdminTab)
            {
                string strLocalizedTabName = GetString(objPortalSettings.ActiveTab.TabName + ".String", "~/App_GlobalResources/GlobalResources.resx");
                if (strLocalizedTabName != "")
                {
                    objPortalSettings.ActiveTab.TabName = strLocalizedTabName;
                    objPortalSettings.ActiveTab.Title = "";
                }
            }
            HttpContext.Current.Items["PortalSettings"] = objPortalSettings;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Localizes the "Built In" Roles
        /// </summary>
        /// <remarks>
        /// Localizes:
        /// -DesktopTabs
        /// -BreadCrumbs
        /// </remarks>
        /// <history>
        /// [cnurse]	02/01/2005	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string LocalizeRole(string role)
        {
            string refStringHelperL0 = role;
            if ((refStringHelperL0 == "All Users") || (refStringHelperL0 == "Superuser"))
            {
            }
            if (((refStringHelperL0 == "Unauthenticated Users") ? 1 : 0) != 0)
            {
                return GetString(role.Replace(" ", ""));
            }
            return role;
        }

        private static ArrayList LocalizeTabStripDetails(ArrayList arrTabStripDetails)
        {
            int refIntHelperL0 = arrTabStripDetails.Count - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                DotNetNuke.Entities.Tabs.TabInfo objTab = (DotNetNuke.Entities.Tabs.TabInfo) arrTabStripDetails[i];
                if (objTab.IsAdminTab)
                {
                    string strLocalizedTabName = GetString(objTab.TabName + ".String", "~/App_GlobalResources/GlobalResources.resx");
                    if (strLocalizedTabName != "")
                    {
                        objTab.TabName = strLocalizedTabName;
                        objTab.Title = "";
                    }
                }
            }
            return arrTabStripDetails;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Does the replacement of tags on a givem message.
        /// </summary>
        /// <param name="MessageValue">The message to be formatted.</param>
        /// <param name="Prefix">The prefix to look for supported tags.</param>
        /// <param name="objObject">An object used to look for replacement values.</param>
        /// <param name="objType">Object type for the object used to look for replacement values.</param>
        /// <returns>The message with the found tags replaced.</returns>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// [Vicen鏬	05/07/2004	Documented
        /// [cnurse]    10/06/2004  Moved from SystemMessages to Localization
        /// </history>
        /// -----------------------------------------------------------------------------
        private static string PersonalizeSystemMessage(string MessageValue, string Prefix, object objObject, Type objType)
        {
            string strPropertyName = "";
            string strPropertyValue = "";
            ArrayList objProperties = CBO.GetPropertyInfo(objType);
            int refIntHelperL0 = objProperties.Count - 1;
            for (int intProperty = 0; intProperty <= refIntHelperL0; intProperty++)
            {
                strPropertyName = ((PropertyInfo) objProperties[intProperty]).Name;
                if (Strings.InStr(1, MessageValue, "[" + Prefix + strPropertyName + "]", CompareMethod.Text) != 0)
                {
                    PropertyInfo propInfo = (PropertyInfo) objProperties[intProperty];
                    object propValue = RuntimeHelpers.GetObjectValue(propInfo.GetValue(RuntimeHelpers.GetObjectValue(objObject), null));
                    if (propValue != null)
                    {
                        strPropertyValue = propValue.ToString();
                    }
                    if (((Prefix + strPropertyName) == "Membership:Password") & (Convert.ToString(RuntimeHelpers.GetObjectValue(DotNetNuke.Common.Globals.HostSettings["EncryptionKey"])) != ""))
                    {
                        strPropertyValue = new PortalSecurity().Decrypt(DotNetNuke.Common.Globals.HostSettings["EncryptionKey"].ToString(), strPropertyValue);
                    }
                    MessageValue = Strings.Replace(MessageValue, "[" + Prefix + strPropertyName + "]", strPropertyValue, 1, -1, CompareMethod.Text);
                }
            }
            return MessageValue;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Returns the TimeZone file name for a given resource and language
        /// </summary>
        /// <param name="filename">Resource File</param>
        /// <param name="language">Language</param>
        /// <returns>Localized File Name</returns>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// [vmasanas]	04/10/2004	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        private string TimeZoneFile(string filename, string language)
        {
            if (language == "en-US")
            {
                return filename;
            }
            return (filename.Substring(0, filename.Length - 4) + "." + language + ".xml");
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// The CurrentCulture returns the current Culture being used
        /// is 'key'.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// [cnurse]	10/06/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public string CurrentCulture
        {
            get
            {
                return Thread.CurrentThread.CurrentCulture.ToString();
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// The KeyName property returns and caches the name of the key attribute used to lookup resources.
        /// This can be configured by setting ResourceManagerKey property in the web.config file. The default value for this property
        /// is 'key'.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// [cnurse]	10/06/2004	Documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string KeyName
        {
            get
            {
                return _defaultKeyName;
            }
            set
            {
                _defaultKeyName = value;
                if ((_defaultKeyName == null) | (_defaultKeyName == string.Empty))
                {
                    _defaultKeyName = "resourcekey";
                }
            }
        }
    }
}

